<template>
  <view style="padding-bottom: 160rpx;">
    <u-navbar
      v-if="!$isWeixin()"
      :title="title"
      :background="{ backgroundColor: '#ffffff' }"
      :titleBold="true"
      :is-fixed="true"
    ></u-navbar>

    <u-tabs active-color="#FF7A23" :list="list" :current="current" @change="handleTabChange"></u-tabs>

    <view class="" v-show="current == 0">
      <u-cell-group>
        <u-cell-item title="类型" :arrow="false" required>
          <u-radio-group v-model="form.ApplyType">
            <u-radio name="1">旗舰店</u-radio>
            <u-radio name="2">专卖店</u-radio>
          </u-radio-group>
        </u-cell-item>

        <u-cell-item title="申请类型" :arrow="false" required>
          <u-radio-group v-model="form.IsCheckInPlatform">
            <u-radio name="1">焕新</u-radio>
            <u-radio name="2">新建</u-radio>
          </u-radio-group>
        </u-cell-item>

        <u-cell-item v-if="form.IsCheckInPlatform == 2" title="二级是否已入驻平台" :arrow="false" required>
          <u-radio-group v-model="form.IsSecondDealer">
            <u-radio name="1">是</u-radio>
            <u-radio name="2">否</u-radio>
          </u-radio-group>
        </u-cell-item>

        <block
          v-if="
            form.IsCheckInPlatform == 1 ||
              form.IsSecondDealer == 1 ||
              (form.IsCheckInPlatform == 2 && form.IsSecondDealer == 2)
          "
        >
          <dealer-select
            ref="dealerSelectFrom"
            :showSecond="!(form.IsCheckInPlatform == 2 && form.IsSecondDealer == 2)"
            @first-change="onFirstDealerChange"
            @second-change="onSecondDealerChange"
            @change="onStoreDealerChange"
            :showStore="form.IsCheckInPlatform == 1"
          ></dealer-select>
        </block>

        <block v-if="form.IsSecondDealer == 2 && form.IsCheckInPlatform == 2">
          <u-cell-item title="一级经销商名称" :arrow="false" required>
            <u-input v-model="form.FirstDealerName" inputAlign="right" placeholder="一级经销商名称"></u-input>
          </u-cell-item>
          <u-cell-item title="二级经销商名称" :arrow="false" required>
            <u-input v-model="form.SecondDealerName" inputAlign="right" placeholder="二级经销商名称"></u-input>
          </u-cell-item>
        </block>

        <block
          v-if="
            form.IsSecondDealer == 2 ||
              (form.IsCheckInPlatform == 2 && form.IsSecondDealer == 1 && form.SecondDealerId) ||
              (form.IsCheckInPlatform == 1 && form.StoreDealerId)
          "
        >
          <u-cell-item title="一级渠道属性" :arrow="false">
            <u-radio-group v-model="form.First_DealerType2">
              <view class="grid-2">
                <u-radio v-for="(item, index) in DealerTypeList" :key="index" :name="item.Key">
                  {{ item.Value }}
                </u-radio>
              </view>
            </u-radio-group>
          </u-cell-item>

          <u-cell-item title="一级经营品类" :arrow="false">
            <u-checkbox-group @change="onFirstBusinessCategoryChange">
              <view class="grid-2">
                <u-checkbox
                  v-model="item.checked"
                  v-for="(item, index) in FirstBusinessCategoryList"
                  :key="index"
                  :name="item.Key"
                >
                  {{ item.Value }}
                </u-checkbox>
              </view>
            </u-checkbox-group>
          </u-cell-item>

          <u-cell-item
            v-if="form.First_BusinessCategory.indexOf(22) > -1"
            title="上一年供暖销售额(万元)"
            :arrow="false"
          >
            <u-input v-model="form.First_LY_HeatingSales" inputAlign="right" placeholder="销售额" />
          </u-cell-item>

          <u-cell-item
            v-if="form.First_BusinessCategory.indexOf(23) > -1"
            title="上一年空调销售额(万元)"
            :arrow="false"
          >
            <u-input v-model="form.First_LY_AirConditionerSales" inputAlign="right" placeholder="销售额" />
          </u-cell-item>

          <u-cell-item
            v-if="form.First_BusinessCategory.indexOf(24) > -1"
            title="上一年净水新风销售额(万元)"
            :arrow="false"
          >
            <u-input v-model="form.First_LY_FreshWaterSales" inputAlign="right" placeholder="销售额" />
          </u-cell-item>

          <u-cell-item title="二级上一年BDR销售额(万元)" :arrow="false">
            <u-input v-model="form.Second_LY_BDRSales" inputAlign="right" placeholder="销售额" />
          </u-cell-item>

          <u-cell-item title="门店上一年BDR销售额(万元)" :arrow="false">
            <u-input v-model="form.Store_LY_BDRSales" inputAlign="right" placeholder="销售额" />
          </u-cell-item>
        </block>
      </u-cell-group>
    </view>

    <view class="" v-show="current == 1">
      <u-cell-group>
        <u-cell-item title="所属品牌" :arrow="false" required>
          <u-radio-group v-model="form.Store_Brand">
            <u-radio v-for="(item, index) in GoodsBrandList" :key="index" :name="item.Key">{{ item.Value }}</u-radio>
          </u-radio-group>
        </u-cell-item>

        <u-cell-item title="门店名称" :arrow="false" required>
          <u-input v-model="form.Store_DealerName" inputAlign="right" placeholder="门店名称" />
        </u-cell-item>

        <u-cell-item title="本次装修门店负责人" :arrow="false" required>
          <u-input v-model="form.DecorateNickName" inputAlign="right" placeholder="本次装修门店负责人" />
        </u-cell-item>

        <u-cell-item title="装修门店负责人手机号" :arrow="false" required>
          <u-input v-model="form.DecorateMobile" inputAlign="right" placeholder="装修门店负责人手机号" />
        </u-cell-item>

        <u-cell-item title="门店负责人" :arrow="false" required>
          <u-input v-model="form.Store_NickName" inputAlign="right" placeholder="门店负责人" />
        </u-cell-item>

        <u-cell-item title="联系人手机号" :arrow="false" required>
          <u-input v-model="form.Store_Mobile" inputAlign="right" placeholder="联系人手机号" />
        </u-cell-item>

        <u-cell-item title="门店地址" :arrow="false" required v-if="loadCity">
          <city-select @city-change="onCityChange" v-model="areaCode"></city-select>
          <u-input inputAlign="right" v-model="form.Store_Address"></u-input>
        </u-cell-item>

        <u-cell-item title="门店位置" :arrow="false" required>
          <u-input
            type="select"
            :value="location.label"
            placeholder="请选择"
            input-align="right"
            @click="showLocationPicker = true"
          ></u-input>
          <u-input inputAlign="right" v-model="form.Store_Location_Other"></u-input>
          <u-select
            @confirm="onLocationChange"
            :default-value="[locationIndex]"
            v-model="showLocationPicker"
            :list="Store_Location_List"
            label-name="Value"
            value-name="Key"
            safe-area-inset-bottom
          ></u-select>
        </u-cell-item>

        <u-cell-item title="门店BDR面积" :arrow="false">
          <u-input v-model="form.BDR_Area" input-align="right" placeholder="BDR面积"></u-input>
        </u-cell-item>
        <u-cell-item title="店内面积" :arrow="false">
          <u-input v-model="form.Store_Area" input-align="right" placeholder="店内面积"></u-input>
        </u-cell-item>
        <u-cell-item title="其他产品占用面积" :arrow="false">
          <u-input v-model="form.OtherProductArea" input-align="right" placeholder="其他产品占用面积"></u-input>
        </u-cell-item>

        <u-cell-item title="人员数量" :arrow="false" style="" :border-bottom="false">
          <u-button @tap="addPersonCount" type="warning" size="mini">添加</u-button>
        </u-cell-item>

        <u-cell-item title="" :arrow="false">
          <view class="u-flex u-text-right" v-for="(item, index) in form.DealerPeopleNumList" :key="index">
            <u-input v-model="item.Title" placeholder="请输入标题" :border="true" :height="50"></u-input>
            <text class="u-m-20">:</text>
            <u-input v-model="item.Num" type="number" placeholder="数量" :border="true" :height="50"></u-input>
            <u-button @tap="removePersonCount(index)" style="margin-left: 20rpx;" type="error" size="mini">
              删除
            </u-button>
          </view>
        </u-cell-item>
      </u-cell-group>
    </view>

    <view class="" v-show="current == 2">
      <u-cell-item :arrow="false" title="经营品类">
        <u-checkbox-group @change="onBusinessCategoryChange">
          <view class="grid-2">
            <u-checkbox
              :label-size="26"
              v-model="item.checked"
              v-for="(item, index) in BusinessCategoryList"
              :name="item.Key"
              :key="index"
            >
              {{ item.Value }}
            </u-checkbox>
          </view>
        </u-checkbox-group>
      </u-cell-item>
      <u-cell-item :arrow="false" title="经营品牌">
        <view class="u-text-left u-p-l-20">BDR品牌数: {{ count_A }}</view>
        <u-checkbox-group @change="onCompetingGoodsBrandAChange">
          <view class="grid-2">
            <u-checkbox
              :label-size="26"
              v-model="item.checked"
              v-for="(item, index) in CompetingGoodsBrandAList"
              :key="index"
              :name="item.Key"
            >
              {{ item.Value }}
            </u-checkbox>
          </view>
        </u-checkbox-group>
        <u-line></u-line>

        <!-- <view class="u-text-left u-p-l-20">进口品牌数: {{ count_B }}</view>
				<u-checkbox-group @change="onCompetingGoodsBrandBChange">
					<view class="grid-2">
						<u-checkbox :label-size="26" v-model="item.checked" v-for="(item, index) in CompetingGoodsBrandBList" :key="index" :name="item.Key">{{ item.Value }}</u-checkbox>
					</view>
				</u-checkbox-group>
				<u-line></u-line>

				<view class="u-text-left u-p-l-20">国产品牌数: {{ count_C }}</view>
				<u-checkbox-group @change="onCompetingGoodsBrandCChange">
					<view class="grid-2">
						<u-checkbox :label-size="26" v-model="item.checked" v-for="(item, index) in CompetingGoodsBrandCList" :key="index" :name="item.Key">{{ item.Value }}</u-checkbox>
					</view>
				</u-checkbox-group> -->
      </u-cell-item>

      <product-information ref="productInformation"></product-information>
    </view>

    <view class="" v-show="current == 3">
      <u-cell-item :arrow="false" title="上一年对应代理商供暖销售额">
        <view class="u-flex-col u-col-bottom">
          <view class="u-flex">
            <u-input
              v-model="form.LY_DealerHeatingSales"
              type="number"
              inputAlign="right"
              placeholder="请输入"
            ></u-input>
            <text class="unit u-m-l-32">万元</text>
          </view>
        </view>
      </u-cell-item>

      <u-cell-item :arrow="false" title="上一年对应代理商空凋销售额">
        <view class="u-flex-col u-col-bottom">
          <view class="u-flex">
            <u-input
              v-model="form.LY_DealerAirConditionerSales"
              type="number"
              inputAlign="right"
              placeholder="请输入"
            ></u-input>
            <text class="unit u-m-l-32">万元</text>
          </view>
        </view>
      </u-cell-item>

      <u-cell-item :arrow="false" title="上一年对应代理商净水销售额">
        <view class="u-flex-col u-col-bottom">
          <view class="u-flex">
            <u-input
              v-model="form.LY_DealerPurifiedWaterSales"
              type="number"
              inputAlign="right"
              placeholder="请输入"
            ></u-input>
            <text class="unit u-m-l-32">万元</text>
          </view>
        </view>
      </u-cell-item>

      <u-cell-item :arrow="false" title="上一年门店供暖销售额">
        <view class="u-flex-col u-col-bottom">
          <view class="u-flex">
            <u-input
              v-model="form.LY_StoreHeatingSales"
              type="number"
              inputAlign="right"
              placeholder="请输入"
            ></u-input>
            <text class="unit u-m-l-32">万元</text>
          </view>
        </view>
      </u-cell-item>

      <u-cell-item :arrow="false" title="上一年门店空凋销售额">
        <view class="u-flex-col u-col-bottom">
          <view class="u-flex">
            <u-input
              v-model="form.LY_StoreAirConditionerSales"
              type="number"
              inputAlign="right"
              placeholder="请输入"
            ></u-input>
            <text class="unit u-m-l-32">万元</text>
          </view>
        </view>
      </u-cell-item>

      <u-cell-item :arrow="false" title="上一年门店净水销售额">
        <view class="u-flex-col u-col-bottom">
          <view class="u-flex">
            <u-input
              v-model="form.LY_Store_BDR_PurifiedWaterSales"
              type="number"
              inputAlign="right"
              placeholder="请输入"
            ></u-input>
            <text class="unit u-m-l-32">万元</text>
          </view>
        </view>
      </u-cell-item>

      <u-cell-item :arrow="false" title="上一年销售BDR供暖产品台数">
        <view class="u-flex-col u-col-bottom">
          <view class="u-flex">
            <u-input
              v-model="form.LY_Store_BDR_HeatingSalesNum"
              type="number"
              inputAlign="right"
              placeholder="请输入"
            ></u-input>
            <text class="unit u-m-l-32">台</text>
          </view>
        </view>
      </u-cell-item>

      <u-cell-item :arrow="false" title="上一年销售BDR净水产品台数">
        <view class="u-flex-col u-col-bottom">
          <view class="u-flex">
            <u-input
              v-model="form.LY_Store_BDR_AirConditionerSalesNum"
              type="number"
              inputAlign="right"
              placeholder="请输入"
            ></u-input>
            <text class="unit u-m-l-32">台</text>
          </view>
        </view>
      </u-cell-item>

      <u-cell-item :arrow="false" title="上一年销售BDR热泵产品台数">
        <view class="u-flex-col u-col-bottom">
          <view class="u-flex">
            <u-input
              v-model="form.LY_Store_BDR_PurifiedWaterSalesNum"
              type="number"
              inputAlign="right"
              placeholder="请输入"
            ></u-input>
            <text class="unit u-m-l-32">台</text>
          </view>
        </view>
      </u-cell-item>
    </view>

    <view class="" v-show="current == 4">
      <u-cell-group>
        <u-cell-item :arrow="false" title="新店所属市级区域供暖市场容量">
          <view class="u-flex-col u-col-bottom">
            <view class="u-flex">
              <u-input
                v-model="form.AS_HeatingMarketCapacity"
                type="number"
                inputAlign="right"
                placeholder="请输入"
              ></u-input>
              <text class="unit u-m-l-32">台</text>
            </view>
          </view>
        </u-cell-item>

        <u-cell-item :arrow="false" title="新店所属市级区域热泵市场容量">
          <view class="u-flex-col u-col-bottom">
            <view class="u-flex">
              <u-input
                v-model="form.AS_HeatPumpMarketCapacity"
                type="number"
                inputAlign="right"
                placeholder="请输入"
              ></u-input>
              <text class="unit u-m-l-32">台</text>
            </view>
          </view>
        </u-cell-item>

        <u-cell-item :arrow="false" title="周边1公里竞品门店数">
          <u-input v-model="form.AS_CompetingStoresNum" type="number" inputAlign="right" placeholder="请输入"></u-input>
        </u-cell-item>

        <u-cell-item :arrow="false" title="周边1公里竞品品牌">
          <u-input v-model="form.AS_CompetingBrand" type="number" inputAlign="right" placeholder="请输入"></u-input>
        </u-cell-item>

        <u-cell-item :arrow="false" title="周边1公里竞品做最好的品牌">
          <u-input v-model="form.AS_BestCompetingBrand" type="number" inputAlign="right" placeholder="请输入"></u-input>
        </u-cell-item>

        <u-cell-item :arrow="false" title="周边1公里竞品做最好品牌的年供暖销售额">
          <view class="u-flex-col u-col-bottom">
            <view class="u-flex">
              <u-input
                v-model="form.AS_AnnualHeatingSalesCompetingProducts"
                type="number"
                inputAlign="right"
                placeholder="请输入"
              ></u-input>
              <text class="unit u-m-l-32">万元</text>
            </view>
          </view>
        </u-cell-item>

        <u-cell-item :arrow="false" title="周边1公里竞品做最好品牌的年热泵销售额">
          <view class="u-flex-col u-col-bottom">
            <view class="u-flex">
              <u-input
                v-model="form.AS_CompetitiveAnnualHeatPumpSales"
                type="number"
                inputAlign="right"
                placeholder="请输入"
              ></u-input>
              <text class="unit u-m-l-32">万元</text>
            </view>
          </view>
        </u-cell-item>

        <block>
          <u-cell-item title="开店原因" :arrow="false" style="padding-bottom: 0;" :border-bottom="false"></u-cell-item>
          <u-cell-item :arrow="false" style="padding: 0rpx 40rpx;">
            <u-input type="textarea" v-model="form.AS_ReasonOpeningStore"></u-input>
          </u-cell-item>
        </block>

        <u-cell-item :arrow="false" title="新店预估年壁挂炉台数">
          <view class="u-flex-col u-col-bottom">
            <view class="u-flex">
              <u-input
                v-model="form.NY_Estimate_FireplaceNum"
                type="number"
                inputAlign="right"
                placeholder="请输入"
              ></u-input>
              <text class="unit u-m-l-32">台</text>
            </view>
          </view>
        </u-cell-item>

        <u-cell-item :arrow="false" title="新店预估年净水台数">
          <view class="u-flex-col u-col-bottom">
            <view class="u-flex">
              <u-input
                v-model="form.NY_Estimate_CleanWaterNum"
                type="number"
                inputAlign="right"
                placeholder="请输入"
              ></u-input>
              <text class="unit u-m-l-32">台</text>
            </view>
          </view>
        </u-cell-item>

        <u-cell-item :arrow="false" title="新店预估年热泵台数">
          <view class="u-flex-col u-col-bottom">
            <view class="u-flex">
              <u-input
                v-model="form.NY_Estimate_HeatPumpNum"
                type="number"
                inputAlign="right"
                placeholder="请输入"
              ></u-input>
              <text class="unit u-m-l-32">台</text>
            </view>
          </view>
        </u-cell-item>

        <!-- <u-cell-item :arrow="false" title="申请类型">
					<u-radio-group v-model="form.StoreApplyType">
						<u-radio name="1">焕新</u-radio>
						<u-radio name="2">新建</u-radio>
					</u-radio-group>
				</u-cell-item> -->

        <u-cell-item :arrow="false" title="渠道补贴">
          <u-radio-group v-model="form.SubsidyMethod">
            <u-radio name="1">现金</u-radio>
            <u-radio name="2">市场返利</u-radio>
          </u-radio-group>
        </u-cell-item>
      </u-cell-group>
    </view>

    <view class="" v-show="current == 5">
      <u-cell-group>
        <u-cell-item :border-bottom="false" title="申请备注" :arrow="false">
          <u-input v-model="form.ApplyRemark" type="textarea" inputAlign="right" placeholder="申请备注"></u-input>
        </u-cell-item>
      </u-cell-group>
    </view>

    <view v-show="current == 6">
      <u-cell-group>
        <u-cell-item title="计划开业时间" required :arrow="false">
          <u-input
            type="select"
            @click="showTimePicker = true"
            :value="plannedTime"
            inputAlign="right"
            :select-open="showTimePicker"
          />
          <u-picker mode="time" v-model="showTimePicker" @confirm="onTimeChange"></u-picker>
        </u-cell-item>

        <u-cell-item title="预装板块" required :arrow="false">
          <u-checkbox-group @change="onPreInstalledPlatesChange">
            <u-checkbox
              v-model="item.checked"
              v-for="(item, index) in Pre_Installed_Plates"
              :key="index"
              :name="item.Key"
            >
              {{ item.Value }}
            </u-checkbox>
          </u-checkbox-group>
        </u-cell-item>

        <u-cell-item title="是否需要储物间" required :arrow="false">
          <u-radio-group v-model="form.IsNeedStorage">
            <u-radio name="1">是</u-radio>
            <u-radio name="2">否</u-radio>
          </u-radio-group>
        </u-cell-item>

        <u-cell-item title="是否通燃气" required :arrow="false">
          <u-radio-group v-model="form.IsPassGas">
            <u-radio name="1">是</u-radio>
            <u-radio name="2">否</u-radio>
          </u-radio-group>
        </u-cell-item>

        <u-cell-item title="是否满足上下水" required :arrow="false">
          <u-radio-group v-model="form.IsUpDownWater">
            <u-radio name="1">是</u-radio>
            <u-radio name="2">否</u-radio>
          </u-radio-group>
        </u-cell-item>
        <u-cell-item title="是否有柱子" required :arrow="false">
          <u-radio-group v-model="form.IsPillar">
            <u-radio name="1">是</u-radio>
            <u-radio name="2">否</u-radio>
          </u-radio-group>
        </u-cell-item>
        <u-cell-item title="" :arrow="false" v-if="form.IsPillar == 1">
          <new-store-photo
            :minUpCount="0"
            v-model="form.Pillar_Photo_List"
            defaultTitle="柱子照片"
            :showDelete="true"
          ></new-store-photo>
        </u-cell-item>

        <u-cell-item title="是否有消防栓" required :arrow="false" :border-bottom="false">
          <u-radio-group v-model="form.IsFireHydrant">
            <u-radio name="1">是</u-radio>
            <u-radio name="2">否</u-radio>
          </u-radio-group>
        </u-cell-item>
        <u-cell-item title="" :arrow="false" v-if="form.IsFireHydrant == 1">
          <new-store-photo
            :minUpCount="0"
            v-model="form.FireHydrant_Photo_List"
            defaultTitle="消防栓照片"
            :showDelete="true"
          ></new-store-photo>
        </u-cell-item>

        <u-cell-item title="门店现场照片" required :arrow="false" :border-bottom="false"></u-cell-item>
        <u-cell-item title="" :arrow="false">
          <new-store-photo
            :minUpCount="3"
            v-model="form.Store_Photo_List"
            defaultTitle="店内现场照片"
          ></new-store-photo>
        </u-cell-item>

        <u-cell-item title="门店CAD图纸" required :arrow="false" :border-bottom="false"></u-cell-item>
        <u-cell-item title="" :arrow="false"><file-picker v-model="form.CAD_Photo_List"></file-picker></u-cell-item>
      </u-cell-group>
    </view>

    <view class="btn-group-fixed">
      <!-- <u-button @click="backToList">返回列表</u-button> -->
      <u-button type="warning" :disabled="btnDisabled" @click="submit">保存提交</u-button>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      btnDisabled: false,
      title: '旗舰店',
      current: 0,
      list: [
        { name: '门店所属信息' },
        { name: '门店基础信息' },
        { name: '产品信息' },
        { name: '销售信息' },
        { name: '门店周边情况' },
        { name: '申请备注' }
      ],

      FirstBusinessCategoryList: [],
      BusinessCategoryList: [],

      DealerTypeList: [],

      GoodsBrandList: [],

      Pre_Installed_Plates: [],

      DataBaseInfo: {
        CompetingGoodsBrandA_BaseList: [],
        CompetingGoodsBrandDoubleSupply: []
      },

      showLocationPicker: false,
      locationIndex: -1,
      location: {},
      Store_Location_List: [],

      areaCode: [],
      loadCity: false,

      CompetingGoodsBrandAList: [],
      CompetingGoodsBrandBList: [],
      CompetingGoodsBrandCList: [],

      showTimePicker: false,

      customStyle: {
        // fontSize: '26rpx',
        color: '#909399'
      },

      plannedTime: '',

      form: {
        ApplyType: '',

        // 门店是否已入驻平台  1是  2否
        IsCheckInPlatform: '',

        // 二级是否已入驻平台 1是 2否
        IsSecondDealer: '',

        FirstDealerId: '',
        SecondDealerId: '',
        StoreDealerId: '',

        // 一级经销商名称
        FirstDealerName: '',
        // 二级经销商名称

        StoreDealerName: '',
        Store_DealerName: '',

        // 一级渠道属性
        First_DealerType2: '',
        // 一级经营品类
        First_BusinessCategory: '',

        //
        First_LY_HeatingSales: '',
        First_LY_AirConditionerSales: '',
        First_LY_FreshWaterSales: '',
        Second_LY_BDRSales: '',
        Store_LY_BDRSales: '',

        // -------门店基础信息 --------
        // 门店所属品牌
        Store_Brand: '',
        // 门店名称
        StoreDealerName: '',

        Store_Location: '',
        Store_Location_Other: '',

        Store_ProvinceId: '',
        Store_CityId: '',
        Store_DistrictId: '',
        Store_Address: '',

        BDR_Area: '',
        Store_Area: '',
        OtherProductArea: '',

        // 本次装修负责人
        DecorateNickName: '',
        // 装修门店负责人手机号
        DecorateMobile: '',

        // 门店负责人
        Store_NickName: '',
        // 联系人手机号
        Store_Mobile: '',

        DealerPeopleNumList: [],
        // -------门店基础信息结束 --------

        // ----------产品信息-----------
        BusinessCategory: '',
        CompetingGoodsBrandA: '',
        CompetingGoodsBrandB: '',
        CompetingGoodsBrandC: '',

        DealerVisitSellList: [],
        DealerSamplingSellList: [],
        Sampling: '',
        DoubleSupply: '',
        DoubleSupplyString: '',
        OtherBrand: '',
        // ----------产品信息结束-----------

        // ---------销售信息--------------
        LY_DealerHeatingSales: '',
        LY_DealerAirConditionerSales: '',
        LY_DealerPurifiedWaterSales: '',
        LY_StoreHeatingSales: '',
        LY_StoreAirConditionerSales: '',
        LY_Store_BDR_PurifiedWaterSales: '',
        LY_Store_BDR_HeatingSalesNum: '',
        LY_Store_BDR_AirConditionerSalesNum: '',
        LY_Store_BDR_PurifiedWaterSalesNum: '',
        // ---------销售信息结束--------------

        // --------门店周边情况-----------
        AS_HeatingMarketCapacity: '',
        AS_HeatPumpMarketCapacity: '',
        AS_CompetingStoresNum: '',
        AS_CompetingBrand: '',
        AS_BestCompetingBrand: '',
        AS_AnnualHeatingSalesCompetingProducts: '',
        AS_CompetitiveAnnualHeatPumpSales: '',
        AS_ReasonOpeningStore: '',
        NY_Estimate_FireplaceNum: '',
        NY_Estimate_CleanWaterNum: '',
        NY_Estimate_HeatPumpNum: '',
        StoreApplyType: '',
        SubsidyMethod: '',
        // -------------------------------

        PlannedOpeningTime: '',
        Flagship_Specialty_Pre_Installed_Plates_List: '',
        IsNeedStorage: '',
        IsPassGas: '',
        IsUpDownWater: '',
        IsPillar: '',
        Pillar_Photo_List: [],
        IsFireHydrant: '',
        FireHydrant_Photo_List: [],
        CAD_Photo_List: [],
        Store_Photo_List: [],
        ApplyRemark: ''
      }
    };
  },

  onLoad(options) {
    this.init();
    uni.setNavigationBarTitle({
      title: this.title
    });
  },

  methods: {
    onSecondDealerChange(e) {
      console.log(e);
      if (e.secondDealerId) {
        this.form.SecondDealerId = e.secondDealerId;
      }
      if (e.firstDealerId) {
        this.form.FirstDealerId = e.firstDealerId;
      }
    },

    onFirstDealerChange(firstDealerId, firstDealerName) {
      this.form.FirstDealerId = firstDealerId;
      this.form.FirstDealerName = firstDealerName;
    },

    onStoreDealerChange(dealerId, e) {
      this.form.StoreDealerId = dealerId;
      this.loadCity = false;

      this.$u.api
        .getFlagshipDealerInfo({ Dealer_Id_Str: [e.FirstDealerId, e.SecondDealerId, dealerId].join() })
        .then(res => {
          const {
            ResultCode,
            DelaerBasicInfoList,
            DealerPeopleNumList,
            FSS_DealerSampling_Sell_List,
            FSS_DealerVisit_Sell_List
          } = res;

          if (ResultCode == 1) {
            if (DelaerBasicInfoList) {
              DelaerBasicInfoList.forEach(dealerInfo => {
                if (dealerInfo.Level == 1) {
                  this.form.First_BusinessCategory = dealerInfo.BusinessCategory;
                  this.form.First_DealerType2 = dealerInfo.DealerType2;

                  this.form.First_LY_HeatingSales = dealerInfo.LY_DealerHeatingSales;
                  this.form.First_LY_FreshWaterSales = dealerInfo.LY_DealerPurifiedWaterSales;
                  this.form.First_LY_AirConditionerSales = dealerInfo.LY_DealerAirConditionerSales;

                  if (dealerInfo.BusinessCategory) {
                    this.FirstBusinessCategoryList.forEach(item => {
                      let checked = dealerInfo.BusinessCategory.split(',').indexOf(String(item.Key)) > -1;
                      this.$set(item, 'checked', checked);
                    });
                  }
                }

                if (dealerInfo.Level == 2) {
                  this.form.Second_LY_BDRSales = dealerInfo.LastYearsBDRSales;
                }

                if (dealerInfo.Level == 3) {
                  this.form.Store_LY_BDRSales = dealerInfo.LastYearsBDRSales;

                  this.form.Store_DealerName = dealerInfo.Name;
                  this.form.Store_Mobile = dealerInfo.Mobile;
                  this.form.Store_NickName = dealerInfo.NickName;

                  this.form.Store_Location_Other = dealerInfo.Store_Location_Other;
                  this.form.BDR_Area = dealerInfo.BDR_Area;
                  this.form.Store_Area = dealerInfo.Store_Area;
                  this.form.OtherProductArea = dealerInfo.OtherProductArea;

                  this.form.LY_DealerHeatingSales = dealerInfo.LY_DealerHeatingSales;
                  this.form.LY_DealerAirConditionerSales = dealerInfo.LY_DealerAirConditionerSales;
                  this.form.LY_DealerPurifiedWaterSales = dealerInfo.LY_DealerPurifiedWaterSales;
                  this.form.LY_StoreHeatingSales = dealerInfo.LY_StoreHeatingSales;
                  this.form.LY_StoreAirConditionerSales = dealerInfo.LY_StoreAirConditionerSales;
                  this.form.LY_Store_BDR_PurifiedWaterSales = dealerInfo.LY_Store_BDR_PurifiedWaterSales;
                  this.form.LY_Store_BDR_HeatingSalesNum = dealerInfo.LY_Store_BDR_HeatingSalesNum;
                  this.form.LY_Store_BDR_AirConditionerSalesNum = dealerInfo.LY_Store_BDR_AirConditionerSalesNum;
                  this.form.LY_Store_BDR_PurifiedWaterSalesNum = dealerInfo.LY_Store_BDR_PurifiedWaterSalesNum;

                  this.form.AS_HeatingMarketCapacity = dealerInfo.AS_HeatingMarketCapacity;
                  this.form.AS_HeatPumpMarketCapacity = dealerInfo.AS_HeatPumpMarketCapacity;
                  this.form.AS_CompetingStoresNum = dealerInfo.AS_CompetingStoresNum;
                  this.form.AS_CompetingBrand = dealerInfo.AS_CompetingBrand;
                  this.form.AS_BestCompetingBrand = dealerInfo.AS_BestCompetingBrand;
                  this.form.AS_AnnualHeatingSalesCompetingProducts = dealerInfo.AS_AnnualHeatingSalesCompetingProducts;
                  this.form.AS_CompetitiveAnnualHeatPumpSales = dealerInfo.AS_CompetitiveAnnualHeatPumpSales;
                  this.form.AS_ReasonOpeningStore = dealerInfo.AS_ReasonOpeningStore;
                  this.form.NY_Estimate_FireplaceNum = dealerInfo.NY_Estimate_FireplaceNum;
                  this.form.NY_Estimate_CleanWaterNum = dealerInfo.NY_Estimate_CleanWaterNum;
                  this.form.NY_Estimate_HeatPumpNum = dealerInfo.NY_Estimate_HeatPumpNum;
                  this.form.StoreApplyType = dealerInfo.StoreApplyType;
                  this.form.SubsidyMethod = dealerInfo.SubsidyMethod;

                  this.areaCode = [dealerInfo.ProvinceId, dealerInfo.CityId, dealerInfo.DistrictId];
                  this.loadCity = true;
                  this.form.Store_Address = dealerInfo.Address;

                  if (dealerInfo.Store_Location) {
                    this.form.Store_Location = dealerInfo.Store_Location;

                    this.locationIndex = this.Store_Location_List.findIndex(
                      item => item.Key == this.form.Store_Location
                    );
                    this.location = {
                      label: this.Store_Location_List[this.locationIndex].Value,
                      value: this.Store_Location_List[this.locationIndex].Key
                    };
                  }

                  if (dealerInfo.BusinessCategory) {
                    this.form.BusinessCategory = dealerInfo.BusinessCategory;

                    this.BusinessCategoryList.forEach(item => {
                      let checked = dealerInfo.BusinessCategory.split(',').indexOf(String(item.Key)) > -1;
                      this.$set(item, 'checked', checked);
                    });
                  }

                  if (dealerInfo.CompetingGoodsBrandA) {
                    this.form.CompetingGoodsBrandA = dealerInfo.CompetingGoodsBrandA;
                    this.CompetingGoodsBrandAList.forEach(item => {
                      let checked = dealerInfo.CompetingGoodsBrandA.split(',').indexOf(String(item.Key)) > -1;
                      this.$set(item, 'checked', checked);
                    });
                  }
                  if (dealerInfo.CompetingGoodsBrandB) {
                    this.form.CompetingGoodsBrandB = dealerInfo.CompetingGoodsBrandB;
                    this.CompetingGoodsBrandBList.forEach(item => {
                      let checked = dealerInfo.CompetingGoodsBrandB.split(',').indexOf(String(item.Key)) > -1;
                      this.$set(item, 'checked', checked);
                    });
                  }
                  if (dealerInfo.CompetingGoodsBrandC) {
                    this.form.CompetingGoodsBrandC = dealerInfo.CompetingGoodsBrandC;
                    this.CompetingGoodsBrandCList.forEach(item => {
                      let checked = dealerInfo.CompetingGoodsBrandC.split(',').indexOf(String(item.Key)) > -1;
                      this.$set(item, 'checked', checked);
                    });
                  }

                  this.form.DoubleSupply = dealerInfo.DoubleSupply;
                  this.form.DoubleSupplyString = dealerInfo.DoubleSupplyString;
                  this.DataBaseInfo.CompetingGoodsBrandDoubleSupply.forEach(item => {
                    let checked =
                      dealerInfo.DoubleSupplyString &&
                      dealerInfo.DoubleSupplyString.split(',').indexOf(String(item.Key)) > -1;
                    this.$set(item, 'checked', checked);
                  });

                  this.$refs.productInformation.init({
                    dealerId: dealerId,
                    DataBaseInfo: this.DataBaseInfo,
                    Sampling: dealerInfo.Sampling,
                    DealerSamplingSellList: FSS_DealerSampling_Sell_List,
                    DoubleSupply: dealerInfo.DoubleSupply,
                    DoubleSupplyString: dealerInfo.DoubleSupplyString,
                    OtherBrand: dealerInfo.OtherBrand
                  });
                }
              });

              if (DealerPeopleNumList) {
                this.form.DealerPeopleNumList = DealerPeopleNumList;
              }
            }

            // if (DealerPeopleNumList) {
            // 	this.form.DealerPeopleNumList = DealerPeopleNumList;
            // }

            // if(FSS_DealerSampling_Sell_List) {
            // 	this.form.DealerSamplingSellList = FSS_DealerSampling_Sell_List;
            // }

            // if(FSS_DealerVisit_Sell_List) {
            // 	this.form.DealerVisitSellList = FSS_DealerVisit_Sell_List
            // }
          }
        });
    },

    submit() {
      let me = this;
      me.btnDisabled = true;
      const productInformationForm = this.$refs.productInformation;
      this.form.DealerVisitSellList = productInformationForm.form.DealerVisitSellList;
      this.form.DealerSamplingSellList = productInformationForm.form.DealerSamplingSellList;
      this.form.Sampling = productInformationForm.form.Sampling;
      this.form.DoubleSupply = productInformationForm.form.DoubleSupply;
      this.form.DoubleSupplyString = productInformationForm.form.DoubleSupplyString;
      this.form.OtherBrand = productInformationForm.form.OtherBrand;

      this.form.StoreApplyType = this.form.IsCheckInPlatform;

      const dealerSelectForm = this.$refs.dealerSelectFrom;
      this.form.FirstDealerId = dealerSelectForm.form.FirstDealerId;
      if (dealerSelectForm.form.FirstDealerName) {
        this.form.FirstDealerName = dealerSelectForm.form.FirstDealerName;
      }

      this.form.SecondDealerId = dealerSelectForm.form.SecondDealerId;
      if (dealerSelectForm.form.SecondDealerName) {
        this.form.SecondDealerName = dealerSelectForm.form.SecondDealerName;
      }

      this.form.StoreDealerId = dealerSelectForm.form.StoreDealerId;
      if (dealerSelectForm.form.StoreDealerName) {
        this.form.StoreDealerName = dealerSelectForm.form.StoreDealerName;
      }

      this.$u.api.flagshipStoreApply(this.form).then(res => {
        const { ResultCode, ResultMessage } = res;
        if (ResultCode === 1) {
          this.$u.toast(ResultMessage);
          setTimeout(() => {
            uni.navigateBack();
          }, 1000);
        } else {
          me.btnDisabled = false;
        }
      });
    },

    handleTabChange(index) {
      this.current = index;
    },

    onFirstBusinessCategoryChange(e) {
      this.form.First_BusinessCategory = e.toString();
    },

    onTimeChange(e) {
      this.plannedTime = `${e.year}-${e.month}-${e.day}`;
      this.form.PlannedOpeningTime = e.timestamp;
    },

    onLocationChange(e) {
      if (!e[0].value || !e[0].label) {
        if (this.Store_Location_List.length > 0) {
          this.location.value = this.Store_Location_List[0].Key;
          this.location.label = this.Store_Location_List[0].Value;
        } else {
          return false;
        }
      } else {
        this.location = e[0];
      }

      this.locationIndex = this.Store_Location_List.findIndex(item => item.Key == this.location.value);
      this.form.Store_Location = this.location.value;
    },

    onCityChange(e) {
      if (e.province) {
        this.form.Store_ProvinceId = e.province.value;
      }
      if (e.city) {
        this.form.Store_CityId = e.city.value;
      }
      if (e.area) {
        this.form.Store_DistrictId = e.area.value;
      }
    },

    addPersonCount() {
      this.form.DealerPeopleNumList.push({
        Title: '',
        Num: ''
      });
    },

    removePersonCount(index) {
      this.form.DealerPeopleNumList.splice(index, 1);
    },

    onBusinessCategoryChange(e) {
      this.form.BusinessCategory = e.toString();
    },
    onCompetingGoodsBrandAChange(e) {
      this.form.CompetingGoodsBrandA = e.toString();
    },
    onCompetingGoodsBrandBChange(e) {
      this.form.CompetingGoodsBrandB = e.toString();
    },
    onCompetingGoodsBrandCChange(e) {
      this.form.CompetingGoodsBrandC = e.toString();
    },

    onPreInstalledPlatesChange(e) {
      this.form.Flagship_Specialty_Pre_Installed_Plates_List = e.toString();
    },

    init() {
      this.$u.api
        .getFlagshipStoreDetail({
          FSS_Id: 0
        })
        .then(res => {
          console.log(res);
          const {
            ResultCode,
            BusinessCategory,
            CompetingGoodsBrandA,
            CompetingGoodsBrandB,
            CompetingGoodsBrandC,
            CompetingGoodsBrandDoubleSupply,
            DealerType,
            GoodsBrand,
            Pre_Installed_Plates,
            Store_Location_List
          } = res;

          if (ResultCode == 1) {
            if (BusinessCategory) {
              this.FirstBusinessCategoryList = JSON.parse(JSON.stringify(BusinessCategory));
              this.BusinessCategoryList = JSON.parse(JSON.stringify(BusinessCategory));
            }

            if (DealerType) {
              this.DealerTypeList = DealerType;
            }

            if (GoodsBrand) {
              this.GoodsBrandList = GoodsBrand;
            }

            if (Store_Location_List) {
              this.Store_Location_List = Store_Location_List;
            }

            if (Pre_Installed_Plates) {
              Pre_Installed_Plates.forEach(item => {
                this.$set(item, 'checked', false);
              });
              this.Pre_Installed_Plates = Pre_Installed_Plates;
            }

            if (CompetingGoodsBrandA) {
              this.CompetingGoodsBrandAList = CompetingGoodsBrandA;
              this.DataBaseInfo.CompetingGoodsBrandA_BaseList = CompetingGoodsBrandA;
            }
            if (CompetingGoodsBrandB) {
              this.CompetingGoodsBrandBList = CompetingGoodsBrandB;
            }
            if (CompetingGoodsBrandC) {
              this.CompetingGoodsBrandCList = CompetingGoodsBrandC;
            }

            if (CompetingGoodsBrandDoubleSupply) {
              CompetingGoodsBrandDoubleSupply.forEach(item => {
                this.$set(item, 'checked', false);
              });
              this.DataBaseInfo.CompetingGoodsBrandDoubleSupply = CompetingGoodsBrandDoubleSupply;
            }

            this.$refs.productInformation.init({
              dealerId: this.form.DealerId,
              DataBaseInfo: this.DataBaseInfo
            });

            this.loadCity = true;
          }
        });
    }
  },

  computed: {
    count_A() {
      if (!this.CompetingGoodsBrandAList) {
        return 0;
      }
      return this.CompetingGoodsBrandAList.filter(item => item.checked).length;
    },
    count_B() {
      if (!this.CompetingGoodsBrandBList) {
        return 0;
      }
      return this.CompetingGoodsBrandBList.filter(item => item.Key != 80).filter(item => item.checked).length;
    },
    count_C() {
      if (!this.CompetingGoodsBrandCList) {
        return 0;
      }
      return this.CompetingGoodsBrandCList.filter(item => item.Key != 81).filter(item => item.checked).length;
    }
  }
};
</script>

<style lang="scss"></style>
